/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023.
 * Description: support applying for huge page memory from the DMA partition.
 * Author: heyuqiang <heyuqiang1@huawei.com>
 * Create: 2023-09-07
 * Note: this file isn't compiled independently, it is includded
 * in hugetlb.c
 */
#ifdef CONFIG_RTOS_MEM_HUGETLB_32
#if defined(CONFIG_ZONE_DMA32)
#define GFP_HUGETLB32 GFP_DMA32
#elif defined(CONFIG_ZONE_DMA)
#define GFP_HUGETLB32 GFP_DMA
#else
#error "GFP_HUGETLB32 no support"
#endif

static bool hugetlb_32;

static void set_hugetlb_32_flag(gfp_t *gfp_mask)
{
	if (hugetlb_32) {
		*gfp_mask &= ~__GFP_HIGHMEM;
		*gfp_mask |= GFP_HUGETLB32;
	}
}

static int __init setup_hugetlb_32(char *arg)
{
	hugetlb_32 = true;
	pr_info("hugetlb_32: allocate 32bit PA addressable huge pages\n");

	return 0;
}
early_param("hugetlb_32", setup_hugetlb_32);
#else
static void set_hugetlb_32_flag(gfp_t *gfp_mask) {}
#endif
